//leadpcnpc.txt - Like basic monst, but leads the PC to a destination, and then
// stops there.
// Memory Cells:
//   Cell 0 - Dialogue node before leading
//   Cell 1,2 - Stuff done flag. When this is set to 1, this pc leads the party.
//	 Cell 3 - Nav point to lead to.
//   Cell4  - dialogue while leading
//   Cell 5 - dialogue after leading

begincreaturescript;

variables;

short i,target;
short got_to_dest = 0;
short is_leading = 0;

body;

beginstate INIT_STATE;
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	if ((is_leading == 0) && (gf(get_memory_cell(1),get_memory_cell(2)) > 0))
		is_leading = 1;
	if ((got_to_dest == 0) && (is_leading > 0)) {
		if (get_ran(1,0,100) < 40)
			give_char_text_bubble(ME,"Please follow me.");
		if (dist_to_pc() > 4)
			stop_moving();
			else if (approach_nav_point(ME,get_memory_cell(3),2))
				got_to_dest = 1;

		}


	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate TALKING_STATE;
	if (is_leading == 0) 
		begin_talk_mode(get_memory_cell(0));
	if (got_to_dest > 0) 
		begin_talk_mode(get_memory_cell(5));
	begin_talk_mode(get_memory_cell(4));
	break;